//
//  MSUploadCardCell.m
//  SocietySale
//
//  Created by Mike on 16/11/3.
//  Copyright © 2016年 Mike. All rights reserved.
//

#import "MSUploadCardCell.h"

@interface MSUploadCardCell ()
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UILabel *subTitleLabel;
@property (nonatomic, strong) GXButton *uploadBtn;
@property (nonatomic, strong) DOImageView *exampleImage;
@property (nonatomic, strong) MSBtnWithDynamicImg *officialBtnImage;
@end

@implementation MSUploadCardCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self initView];
    }
    return self;
}

- (void)initView {
    self.titleLabel = [self creatLabel:CGRectMake(12, 0, SCREEN_WIDTH, 50)];
    self.exampleImage = [self creatImage:CGRectMake(35, _titleLabel.bottom, (SCREEN_WIDTH-50-70)/2, 80)];
    
    self.officialBtnImage = [MSBtnWithDynamicImg buttonWithType:UIButtonTypeCustom];
    self.officialBtnImage.frame = CGRectMake(SCREEN_WIDTH/2+25, _titleLabel.bottom, (SCREEN_WIDTH-50-70)/2, 80);
    [self.officialBtnImage addTarget:self action:@selector(uploadClick) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:self.officialBtnImage];
    
    self.subTitleLabel = [self creatLabel:CGRectMake(0, _exampleImage.bottom, SCREEN_WIDTH/2, 35)];
    self.subTitleLabel.textAlignment = NSTextAlignmentCenter;
    
    _uploadBtn = [GXButton buttonWithType:UIButtonTypeCustom];
    _uploadBtn.relayout = YES;
    _uploadBtn.frame = CGRectMake(SCREEN_WIDTH/2, _exampleImage.bottom, SCREEN_WIDTH/2, 35);
    _uploadBtn.titleLabelFrame = CGRectMake(_uploadBtn.width/2-40, 0, 80, 35);
    _uploadBtn.imageViewFrame = CGRectMake(_uploadBtn.width/2+20, 10, 15, 15);
    [_uploadBtn setImage:[UIImage imageNamed:@"shangchuan"] forState:UIControlStateNormal];
    [_uploadBtn setTitle:@"重新上传" forState:UIControlStateNormal];
    [_uploadBtn setTitleColor:kBlueColor forState:UIControlStateNormal];
    _uploadBtn.titleLabel.font = HeitiFont(14);
    [_uploadBtn addTarget:self action:@selector(uploadClick) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:_uploadBtn];
    
    UIView *footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 165, SCREEN_WIDTH, 10)];
    footerView.backgroundColor = kDefaultViewBackgroundColor;
    [self.contentView addSubview:footerView];
    
    UIView *horizonLineView =[[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 0.6)];
    horizonLineView.backgroundColor = kNormalGray;
    [footerView addSubview:horizonLineView];
}

//创建label
- (UILabel*)creatLabel:(CGRect)frame{
    UILabel *label = [[UILabel alloc] initWithFrame:frame];
    label.font = HeitiFont(14);
    label.textColor = kLightBlackColor;
    [self.contentView addSubview:label];
    return label;
}

//创建label
- (DOImageView*)creatImage:(CGRect)frame{
    DOImageView *image = [[DOImageView alloc] initWithFrame:frame];
    [self.contentView addSubview:image];
    return image;
}

- (void)setUploadModel:(MSUploadModel *)uploadModel{
    _uploadModel = uploadModel;
    self.titleLabel.text = _uploadModel.title;
    self.subTitleLabel.text = _uploadModel.subTitle;
    self.exampleImage.imgURLStr = _uploadModel.exampleImage;
    
    if (uploadModel.haveUpload) {
        self.officialBtnImage.frame = CGRectMake(SCREEN_WIDTH/2+25, _titleLabel.bottom, (SCREEN_WIDTH-50-70)/2, 80);
        self.officialBtnImage.imgUrl = nil;
        if (_uploadModel.selectImage) {
            [self.officialBtnImage setImage:_uploadModel.selectImage forState:UIControlStateNormal];
        }
        else{
            self.officialBtnImage.imgUrl = _uploadModel.officialImage;
        }
        _uploadBtn.hidden = NO;
    }
    else{
        self.officialBtnImage.frame = CGRectMake(SCREEN_WIDTH/2+(SCREEN_WIDTH/2-88)/2, _titleLabel.bottom, 80, 80);
        self.officialBtnImage.imgUrl = @"addphonto";
        _uploadBtn.hidden = YES;
    }
}

- (void)uploadClick{
    if ([self.delegate respondsToSelector:@selector(clickCellIndex:)]) {
        [self.delegate clickCellIndex:self.cellIndex];
    }
}

@end
